<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP '分类' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="<%=basePath%>/Source/assets/styles/mif-tree.css">
	<script type="text/javascript" src="<%=basePath%>/javascript/mootools.js"></script>
	<script type="text/javascript" src="<%=basePath%>/javascript/mootools-jsonp.js"></script>
	<script type="text/javascript" src="<%=basePath%>/javascript/Builder.js"></script>
	<script type="text/javascript">Builder.root='<%=basePath%>/';Builder.includeType('source');</script>
	<script type="text/javascript" src="<%=basePath%>/javascript/Servlet.js"></script>
	
	<script type="text/javascript">
	//定义树对象
	var invTree ;
	var url = "<%=basePath%>/servlet/InventoryClassServlet";
	//初始化加载树
	window.addEvent('domready',function(){
		invTree = new InventoryClassTree(url);
	});

	function clickButton(){
		if(invTree.isSelectedEffectNode()){//如果选择的有效节点
			alert(invTree.getSelectedNode().id+" | "+invTree.getSelectedNode().name);
		}
	}
	function loadInventoryClassTree(){
		$("tree_container").empty();
		invTree = new InventoryClassTree(url);
	}
	
	function addInventoryClass(){
		if(!invTree||!invTree.getSelectedNode()){
			alert("请选择要添加的节点");
			return;
		}
		var parentCinvCcode = invTree.getSelectedNode().id;
		//alert($('CinvCcode').value);
		var sv = new Servlet("add");
		sv.data.parentCinvCcode = parentCinvCcode;//父节点编号
		sv.data.cinvCcode = $('CinvCcode').value;//编号 顶级为01-99 二级为 001-999 三级为001-999
		sv.data.cinvCname = $('CinvCname').value;//名称
		sv.data.iinvCgrade = $('IinvCgrade').value;//级别 顶级为1 二级为2 三级为3 ,不能添加4级
		sv.responseCall = addinvResponse;//添加成功后的回调
		sv.submit(url);
		
		
		function addinvResponse(json,text){
			alert("添加成功");
		}
	}
	</script>
  </head>
  
  <body>
    <li><input type="button" value="获取分类树" onclick="loadInventoryClassTree()"></input> &nbsp; <input type="button" onclick="clickButton()" value="打印" >
    
    <h1>Simple Tree example</h1>
	<div id="tree_container" style="height: 400px;width: 500"></div>
	
	<label>*分类号(顶级为01-99 二级为 001-999 三级为001-999)</label><br><input id="CinvCcode" type="text" ><br>
	<label>*名称</label><br><input id="CinvCname" type="text" ><br>
	<label>*IinvCgrade 级别(顶级为1 二级为2 三级为3 ,不能添加4级)</label><br><input id="IinvCgrade" type="text" ><br>
	<li><input type="button" value="添加分类" onclick="addInventoryClass()"/><br>
  </body>
</html>
